package com.example.fengshoutong.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.fengshoutong.R;

import java.util.ArrayList;
import java.util.List;

/**
 * 农技学堂标题适配器
 */
public class SchoolTitleAdapter extends RecyclerView.Adapter<SchoolTitleAdapter.ViewHolder> {
    private List<String> mDataList = new ArrayList<>();
    private View.OnClickListener listener;

    public SchoolTitleAdapter(List<String> dataList) {
        this.mDataList = dataList;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_school_title, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    public void setListener(View.OnClickListener listener) {
        this.listener = listener;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        String data = mDataList.get(position);
        holder.text_title.setText(data);
        holder.itemView.setOnClickListener(listener);
    }

    @Override
    public int getItemCount() {
        if (mDataList != null) {
            return mDataList.size();
        }
        return 0;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView text_title;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            text_title = itemView.findViewById(R.id.text_title);
        }
    }
}
